package com.sgb.kjwl.view.ui.activity.transport;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;
import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityGoodsInfoManagerList3Binding;
import com.sgb.kjwl.di.transport.DaggerTransportComponent;
import com.sgb.kjwl.di.transport.TransportModule;
import com.sgb.kjwl.model.entity.transport.GoodsInfoEntity3;
import com.sgb.kjwl.view.ui.adapter.transport.GoodsInfoManagerListAdapter3;
import com.sgb.kjwl.viewmodel.transport.GoodsInfoManagerModel3;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

import javax.inject.Inject;

public class GoodsInfoManagerListActivity3 extends AppActivity {

    private ActivityGoodsInfoManagerList3Binding binding;
    private GoodsInfoManagerListAdapter3 adapter;

    @Inject
    GoodsInfoManagerModel3 managerModel;

    public static void start(Context context){
        Intent intent = new Intent(context,GoodsInfoManagerListActivity3.class);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

        DaggerTransportComponent.builder().appComponent(appComponent).transportModule(new TransportModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(GoodsInfoManagerListActivity3.this, R.layout.activity_goods_info_manager_list3);

        binding.ivBack.setOnClickListener(this);
        binding.ivSearch.setOnClickListener(this);
        binding.rightView.setOnClickListener(this);

        adapter = new GoodsInfoManagerListAdapter3(this,null);
        binding.goodsInfoManagerList.setLayoutManager(new GridLayoutManager(this,1));
        binding.goodsInfoManagerList.setAdapter(adapter);
        adapter.setOnItemClick(new AdapterOnItemClick<GoodsInfoEntity3>() {
            @Override
            public void onItemClick(GoodsInfoEntity3 goodsInfoEntity3, int position) {
                GoodsInfoDetailActivity3.start(GoodsInfoManagerListActivity3.this,goodsInfoEntity3.getGoodsInfoId()+"");
            }
        });

    }

    @Override
    protected void init() {
        managerModel.getGoodsSourcesList();
    }

    public void getGoodsSourcesList(List<GoodsInfoEntity3> list){
        adapter.setDatas(list);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);

        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.iv_search:
                //搜索
                GoodsInfoManageSearchActivity3.start(GoodsInfoManagerListActivity3.this);
                break;
            case R.id.right_view:
                //发布
                GoodsInfoPublicSourceActivity3.start(GoodsInfoManagerListActivity3.this);
                break;
        }
    }
}
